Skip to main content

Deployment

Learn how to deploy your trading algorithms to AWS Lambda or Azure Functions using the built-in CLI.

Overview

The Investing Algorithm Framework includes a CLI tool (iaf) that handles scaffolding and deployment to cloud platforms. Two deployment targets are supported out of the box:

  • AWS Lambda — Serverless deployment using boto3, with an S3 bucket for state persistence.
  • Azure Functions — Serverless deployment using the Azure SDK, with blob storage for state persistence.

Scaffolding a Project

Use iaf init to generate a project skeleton for your chosen deployment target:

# Default project (local execution)
iaf init

# Project with a web interface
iaf init --type default_web

# AWS Lambda project
iaf init --type aws_lambda

# Azure Function project
iaf init --type azure_function

Options

OptionDefaultDescription
--typedefaultProject type: default, default_web, aws_lambda, or azure_function.
--pathCurrent directoryPath to the directory where the project will be created.
--replaceFalseIf set, existing files will be overwritten.

Each template generates the appropriate entry point, requirements file, configuration files, and deployment scaffolding for the chosen platform.

Deploying to AWS Lambda

The iaf deploy-aws-lambda command packages your project, creates (or updates) an AWS Lambda function, and sets up an S3 bucket for state persistence.

Prerequisites

  • AWS credentials configured (via aws configure or environment variables)
  • Python 3.10+ and boto3 installed
  • Docker installed (for building the deployment package)

Command

iaf deploy-aws-lambda \
--lambda_function_name my-trading-bot \
--region us-east-1

Options

OptionRequiredDefaultDescription
--lambda_function_nameYesName of the Lambda function to create or update.
--regionYesAWS region (e.g., us-east-1, eu-west-1).
--project_dirNoCurrent directoryPath to the project directory containing your code.
--memory_sizeNo3000Memory allocation in MB for the Lambda function.
-e KEY VALUENoEnvironment variables. Can be repeated: -e API_KEY xxx -e SECRET yyy.

What It Does

  1. Packages your project code into a deployment zip.
  2. Creates an IAM role for Lambda execution (if it doesn't exist).
  3. Creates an S3 bucket for state storage (named after the function).
  4. Deploys the Lambda function with the specified memory and environment variables.
  5. Sets the AWS_S3_STATE_BUCKET_NAME environment variable on the function automatically.

Example

# Deploy with environment variables for exchange credentials
iaf deploy-aws-lambda \
--lambda_function_name btc-trading-bot \
--region eu-west-1 \
--memory_size 3000 \
-e BITVAVO_API_KEY your_key \
-e BITVAVO_API_SECRET your_secret

Deploying to Azure Functions

The iaf deploy-azure-function command deploys your project as an Azure Function App, creating the necessary resource group, storage account, and function app.

Prerequisites

  • Azure CLI installed and authenticated (az login), or use --skip_login in CI/CD
  • Azure Functions Core Tools installed (npm install -g azure-functions-core-tools@4)
  • Python 3.10+

Command

iaf deploy-azure-function \
--resource_group my-resource-group \
--deployment_name my-trading-bot \
--region westeurope

Options

OptionRequiredDefaultDescription
--resource_groupYesAzure resource group name.
--deployment_nameYesName for the Function App.
--regionYesAzure region (e.g., westeurope, eastus).
--subscription_idNoDefault subscriptionAzure subscription ID.
--storage_account_nameNoAuto-generatedName for the Azure Storage account.
--container_nameNoiafcontainerBlob container name for state storage.
--create_resource_group_if_not_existsNoFalseCreate the resource group if it doesn't exist.
--skip_loginNoFalseSkip az login (useful for CI/CD pipelines).

What It Does

  1. Verifies Azure Functions Core Tools are installed.
  2. Creates the resource group (if --create_resource_group_if_not_exists is set).
  3. Creates or reuses a storage account and blob container for state.
  4. Deploys the Function App using Azure Functions Core Tools.
  5. Reads .env file from your project directory and sets those values as Function App configuration.

Example

# Deploy with a new resource group
iaf deploy-azure-function \
--resource_group trading-bots-rg \
--deployment_name btc-trader \
--region westeurope \
--create_resource_group_if_not_exists

Project Templates

When you run iaf init, the framework generates different files depending on the --type:

Default (default)

  • app.py — Main entry point with create_app() and app.start()
  • strategy.py — Example TradingStrategy subclass
  • data_providers.py — Example data provider setup
  • requirements.txt — Python dependencies
  • .env.example — Template for environment variables
  • .gitignore — Standard Python gitignore

AWS Lambda (aws_lambda)

Everything from default, plus:

  • app.py — Lambda handler entry point
  • Dockerfile — Container image for Lambda deployment
  • .dockerignore — Files to exclude from the Docker image
  • requirements.txt — Includes boto3 and framework dependencies
  • README.md — Lambda-specific deployment instructions

Azure Function (azure_function)

Everything from default, plus:

  • function_app.py — Azure Function entry point
  • host.json — Azure Functions host configuration
  • local.settings.json — Local development settings
  • requirements.txt — Includes Azure SDK dependencies
  • .env.example — Azure-specific environment variables

Environment Variables

Both deployment targets support environment variables for sensitive configuration. Store exchange API keys and other secrets as environment variables rather than in code.

For AWS Lambda, use the -e flag during deployment:

iaf deploy-aws-lambda \
--lambda_function_name my-bot \
--region us-east-1 \
-e BITVAVO_API_KEY your_key \
-e BITVAVO_API_SECRET your_secret

For Azure Functions, add variables to your .env file in the project root. The deploy command reads this file and sets them as Function App configuration:

# .env
BITVAVO_API_KEY=your_key
BITVAVO_API_SECRET=your_secret

Next Steps

With your bot deployed, refer to the Trading Strategies and Backtesting documentation to refine your algorithms before going live.